<!--购物车加减-->
<template>
  <div class="addSubtractButton">
    <input v-model="quantity" type="number" />
    <div>
      <a href="javascript:;" @click="handleAdd">+</a>
      <a href="javascript:;" @click="handleSubtract">-</a>
    </div>
  </div>
</template>
<script>
export default {
  name: "AddSubtractButton",
  data() {
    return {
      quantity: 0,
    };
  },
  methods: {
    handleSubtract() {
      if (this.quantity == 0) {
        this.$emit("update-quantity", this.quantity);
        return (this.quantity = 0);
      }
      this.quantity--;
      this.$emit("update-quantity", this.quantity);
    },
    handleAdd() {
      this.quantity++;
      this.$emit("update-quantity", this.quantity);
    },
  },
};
</script>

<style>
.addSubtractButton {
  width: 50px;
  height: 40px;
  position: relative;
  float: left;
  margin-top: 10px;
}

.addSubtractButton input {
  width: 30px;
  height: 100%;
  box-sizing: border-box;
}

.addSubtractButton a {
  display: block;
  text-align: center;
  line-height: 20px;
  background: rgba(0, 0, 0, 0.5);
  width: 20px;
  height: 20px;
  position: absolute;
  right: 0;
  top: 0;
}
.addSubtractButton a:last-child {
  top: 20px;
  right: 0;
}
</style>
